﻿#pragma once


#include "MaterialGraph/Node/MaterialGraphNodeModel.h"
#include "Texture/Texture2D.h"
#include "MaterialTextureNodeModel.m.h"


//out put mesh/vertice properties, like position, uv
RCLASS()
class RMaterialTextureNodeModel : public RMaterialGraphNodeModel
{
    ROBJECT
    
public:
    virtual void FirstTimeInitializeObject() override;

    virtual CString GenerateExpression() override;

    void SetTexture(TSharedObjectPtr<RTexture2D> InTexture);
    TSharedObjectPtr<RTexture2D> GetTexture() const { return Texture; }

    virtual void CollectParameterAndTextures(
        TVector<float>& InOutFloatParameters 
        ,TVector<TSharedObjectPtr<RTexture2D>>& InOutTexture2Ds
        ,TMap<CString,SMaterialParameterDescription>& InOutParameterDescriptions
    ) override;

protected:

    //纹理,不应当为空，避免在编译时出错
    RFIELD()
    TSharedObjectPtr<RTexture2D> Texture;

    //纹理在纹理数组中的索引
    //在编译时设置
    int64_t TextureIndex = 0;


public:
    void SetIsParameter(bool InIsParameter);
    TDelegate<void> OnIsParameterChanged;
protected:
    //是否是参数,参数是可以在运行时修改的
    RFIELD()
    bool bIsParameter = false;

public:
    //能不能转换成参数
    virtual bool CanConvertToParameter() const override { return !bIsParameter; }
    //能不能改出参数
    virtual bool CanConvertFromParameter() const override{ return bIsParameter; }
    //是不是参数节点
    virtual bool IsParameter() const override{ return bIsParameter; }
    //获取参数名字
    virtual CString GetParameterName() const override{ return ParameterName; }
    //设置参数名字
    virtual void SetParameterName(const CString& InName) override{ ParameterName=InName;}

    //参数名,如果是参数的话,这个参数名会在材质编辑器中显示
    //在运行时可以通过这个名字修改参数
    RFIELD()
    CString ParameterName;

};